<!--{include(file='head.html')}-->
<script type="text/javascript" src="template/jslib/tbox/tbox.js"></script>
<link rel="stylesheet" href="template/jslib/tbox/tbox.css" type="text/css" />
<script type="text/javascript" src="template/jslib/xheditor/xheditor.js"></script>
<script type="text/javascript" src="template/jslib/upload/ajaxupload.js"></script>
<script type="text/javascript">
function createupload(buttonid) {
	var uploader = new qq.FileUploader({ //申明一个upload
		 element: document.getElementById(buttonid),
		 action: "<!--{url('admin','uploadfile','specselfpic')}-->"+"&buttonid="+buttonid
	});
}
</script>
<div id="wrap">
	<!--{include('left.html')}-->
	<div id="maincont">
		<b class="b1"></b><b class="b2"></b><b class="b3"></b><b class="b4"></b>
		<div id="main_c" >
			<form action="<!--{url('admin','item','itemsave')}-->" method="post" name="submitform" id="submitform" onsubmit="return formcheck();">
			<div id="infotab">
				<ul>
					<li class="cur"><a href="javascript:void(0);" id="a_base" onclick="$.oper.jstab('a_base');return false;">基本信息</a></li>
					<li><a href="javascript:void(0);" id="a_desc" onclick="$.oper.jstab('a_desc');return false;">商品详情</a></li>
					<li><a href="javascript:void(0);" id="a_seo" onclick="$.oper.jstab('a_seo');return false;">SEO</a></li>
					<li><a href="javascript:void(0);" id="a_rel" onclick="$.oper.jstab('a_rel');return false;">相关商品</a></li>
				</ul>
			</div>
			<div id="forbase" class="bk">
					<ul class="bk_2 clearfix">
						<li>
							<label><em>*</em>商品类目：</label>
							<p>
			<select name="typeid" id="typeid"onchange="window.location.href='<!--{url('admin','item','itemadd')}-->&typeid='+this.value">
				<option value="0">请选择</option>
				<!--{$typeopt}-->
			</select> （<a href="<!--{url('admin','type','typeadd')}-->">添加类目</a>）
							</p>
						</li>
						<li>
							<label><em>*</em>商品名称：</label>
							<p>
								<input class="input_tx long" name="itemname" id="itemname" type="text" value="<!--{$item.itemname}-->"/>
							</p>
						</li>

						<li>
							<label>商品编号：</label>
							<p>
								<input class="input_tx" name="bn" type="text"  value="<!--{$item.bn}-->"/>
							</p>
						</li>

						<!--{foreach $properties property}-->
						<li>
							<label><!--{$property.propertyname}-->：</label>
							<p>
								<!--{if $property.dptype==1 || $property.dptype == 2}-->
									<select name="property[<!--{$property.propertyid}-->]">
										<option value="0">请选择</option>
										<!--{foreach $property[selvallist] key selval}-->
										<option value="<!--{$key}-->"
											<!--{if $selproperties[$property[propertyid]][propertyvalueid] == $key}-->selected<!--{/if}-->
										><!--{$selval}--></option>
										<!--{/foreach}-->
									</select>
								<!--{else}-->
									<input type="text" value="<!--{$selproperties[$property[propertyid]][self]}-->" class="input_tx"  name="property[self_<!--{$property.propertyid}-->]" />
								<!--{/if}-->
							</p>
						</li>
						<!--{/foreach}-->
						<!--{if $brandopt}-->
						<li>
							<label>品牌：</label>
							<p>
								<select name="brandid" id="brandid">
									<option value="0">请选择</option>
									<!--{$brandopt}-->
								</select>
							</p>
						</li>
						<!--{/if}-->
					</ul>

					<!--{if $specs}-->
					<ul class="bk_4">
						<li>
							<label>规格：</label>
							<p>
								<a href="javascript:void(0);" class="bt_style2" onclick="togglespec(this);return false;">
									<!--{if $products}-->关闭规格<!--{else}-->开启规格<!--{/if}-->
								</a>
							</p>
						</li>
					</ul>

					<table class="tableStyle <!--{if !$products}-->none<!--{/if}-->" id="forspec" border="0" cellspacing="0" cellpadding="0">
						<tbody>
							<!--{foreach $specs spec}-->
								<!--{$specid = $spec.specid}-->
								<tr>
									<td width="20%">
										<!--{$spec.name}-->
									</td>
									<td>
										<ul id="spec<!--{$specid}-->">
											<!--{foreach $specvals[$specid] specval}-->
												<!--{$specvalid = $specval.specvalid}-->
												<!--{$tmp = in_array($specvalid,$itemspec[$specid][sel])}-->
											<li>
<input type="checkbox" onclick="check(this,'<!--{$spec.type}-->')" autocomplete="off" value="<!--{$spec.specid}-->_<!--{$specval.specvalid}-->"
	<!--{if $tmp}-->class='shouldclick'<!--{/if}-->
/>
<!--{if $spec.type == "pic"}-->
<img src="<!--{$specval.img}-->" width="16" height="16" class="mid"/>
<!--{/if}-->
<span>
	<!--{if $tmp}-->
		<!--{$itemspec[$specid][text][$specvalid]}-->
	<!--{else}-->
		<!--{$specval.name}-->
	<!--{/if}-->
</span>
											</li>
											<!--{/foreach}-->
										</ul>
<!--{if $spec.type == "pic"}-->
<table class="tableStyle" style="width:100%" border="0" cellspacing="0" cellpadding="0">
		<thead>
			<tr align="center">
				<th width="30%">图片</th>
				<th width="30%">自定义（无图片可不传）</th>
				<th width="40%">图片</th>
			</tr>
		</thead>
		<tbody>
			<!--{foreach $specvals[$specid] specval}-->
				<!--{$specvalid = $specval.specvalid}-->
				<!--{$tmp = in_array($specvalid,$itemspec[$specid][sel])}-->
<tr align="center" id="pic_<!--{$spec.specid}-->_<!--{$specval.specvalid}-->" <!--{if !$tmp}-->class="none"<!--{/if}--> >
	<td id="name_<!--{$specval.specvalid}-->">
		<!--{if $tmp}-->
			<!--{$itemspec[$specid][text][$specvalid]}-->
		<!--{else}-->
			<!--{$specval.name}-->
		<!--{/if}-->
	</td>
	<td>
		<span id="upload_<!--{$specid}-->_<!--{$specvalid}-->"></span>
		<!--{if $tmp}-->
		<script type="text/javascript">
			createupload("upload_<!--{$specid}-->_<!--{$specvalid}-->")
		</script>
		<!--{/if}-->
	</td>
	<td>
		<span id="uploadpic_<!--{$specval.specvalid}-->">
		<!--{if $tmp && $itemspec[$specid][pic][$specvalid]}-->
			<img src="<!--{$itemspec[$specid][pic][$specvalid]}-->_50x50.jpg" width="50" height="50" class="mid"/>
		<!--{/if}-->
		</span>
		<input type="hidden" value="<!--{if $tmp && $itemspec[$specid][pic][$specvalid]}--><!--{$itemspec[$specid][pic][$specvalid]}--><!--{/if}-->" name="selfpic[<!--{$specid}-->][<!--{$specvalid}-->]" id="uploadval_<!--{$specval.specvalid}-->"/>
	</td>
</tr>
			<!--{/foreach}-->
		</tbody>
</table>
<!--{/if}-->

									</td>
								</tr>
							<!--{/foreach}-->
							<tr>
								<td colspan="2">
									<table class="tableStyle" border="0" cellspacing="0" cellpadding="0">
										<thead>
											<tr align="center">
												<td width="10%">操作</td>
											<!--{foreach $specs spec}-->
													<td class="forspec_<!--{$spec.specid}-->" width="10%"><!--{$spec.name}--></td>
											<!--{/foreach}-->
												<td width="20%">价格</td>
												<td width="20%">数量</td>
												<td width="20%">商家编码</td>
											</tr>
										</thead>
										<tbody id="products">
<!--{foreach $products product}-->
<tr align="center">
	<td><a href="javascript:void(0);" class="del" onclick="$.oper.del(this);return false;"></a></td>
	<!--{foreach $specs spec}-->
		<!--{$specid	= $spec[specid]}-->
		<!--{$specvalid = $product[specs][$specid]}-->
		<td class="forspecnone_<!--{$specid}-->">
			<!--{if $spec.type == "pic"}-->
				<a href="javascript:void(0);" onclick="$.specval.select(this,<!--{$specid}-->);return false;">
<!--{if $itemspec[$specid][pic][$specvalid]}-->
	<img src="<!--{$itemspec[$specid][pic][$specvalid]}-->_50x50.jpg"			
		 title="<!--{$itemspec[$specid][text][$specvalid]}-->" width="30" height="30" class="mid img_<!--{$specid}-->_<!--{$specvalid}-->"/>
<!--{else}-->
	<img src="<!--{$specvals[$specid][$specvalid][img]}-->"	
		 title="<!--{$specvals[$specid][$specvalid][name]}-->" width="30" height="30" class="mid img_<!--{$specid}-->_<!--{$specvalid}-->"/>
<!--{/if}-->
				</a>
			<!--{else}-->
			<a href="javascript:void(0);" onclick="$.specval.select(this,'<!--{$specid}-->');return false;">
<!--{def($itemspec[$specid][text][$specvalid],$specvals[$specid][$specvalid][name])}-->
			</a>
			<!--{/if}-->
			<input type="hidden" value="<!--{$specvalid}-->" name="spec[<!--{$specid}-->][key_<!--{$product.productid}-->]"/>
		</td>
	<!--{/foreach}-->
	<td><input type="text" value="<!--{getPrice($product.price)}-->" name="pprice[key_<!--{$product.productid}-->]" class="input_tx mini calprice" onblur="cal('price')"/></td>
	<td><input type="text" value="<!--{$product.inventory}-->" name="pinventory[key_<!--{$product.productid}-->]" class="input_tx mini calinventory" onblur="cal('inventory')"/></td>
	<td>
		<input type="text" value="<!--{$product.bn}-->" name="pbn[key_<!--{$product.productid}-->]" class="input_tx short"/>
	</td>
</tr>
<!--{/foreach}-->
										</tbody>
									</table>
									<p class="add">
										<a class="bt_style2" onclick="addProduct();return false;" href="javascript:void(0);">添加货品</a>
									</p>
								</td>
							</tr>
						</tbody>
					</table>
					<!--{/if}-->
					<ul class="bk_4">
						<li>
							<label><em>*</em>商品价格：</label>
							<p>
								<input class="input_tx mini" name="price" id="price" type="text" value="<!--{getPrice($item.price)}-->"/>
								（开启规格后，价格必须在货品价格之间）
							</p>
						</li>
						<li>
							<label>价格举报：</label>
							<p>
								<input value="1" style="height:16px;" autocomplete="off" name="comprice" id="comprice" type="checkbox"
								<!--{if $item.comprice}-->checked<!--{/if}-->  />
							</p>
						</li>
						<li>
							<label>降价通知：</label>
							<p>
								<input value="1" style="height:16px;" autocomplete="off" name="pnotify" id="pnotify" type="checkbox"
								<!--{if $item.pnotify}-->checked<!--{/if}-->  />
							</p>
						</li>
						<li>
							<label>市场价格：</label>
							<p>
								<input class="input_tx mini" name="mkprice" type="text" value="<!--{getPrice($item.mkprice)}-->"/>
							</p>
						</li>
						<li>
							<label><em>*</em>商品库存：</label>
							<p>
								<input class="input_tx mini" name="inventory" id="inventory" type="text" value="<!--{$item.inventory}-->"/>
								（开启规格后，库存必须为所有货品库存之和）
							</p>
						</li>
						<li>
							<label>赠送积分：</label>
							<p>
								<input class="input_tx mini" name="point" type="text" value="<!--{$item.point}-->"/>
							</p>
						</li>
						<li>
							<label>商品状态：</label>
							<p>
								<input name="status" type="radio" value="1"  id="sale" 
								<!--{if $item.status == 1}-->checked<!--{/if}-->>出售中
								<input name="status" type="radio" value="2" id="stock"
								<!--{if $item.status == 2}-->checked<!--{/if}-->/>放入仓库
							</p>
						</li>
					</ul>
					
					<ul class="bk_4 clearfix">
						<li>
							<label>分类及Tag：</label>
							<div>
								<ul class="scrollul">
									<h1>商品分类</h1>
									<!--{foreach $cats cat}-->
									<li>
										<!--{str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;",$cat['level'])}-->
										<!--{if !$cat["haschild"]}-->
											<input type="checkbox" value="<!--{$cat.catid}-->" name="catid[]" id="cat_<!--{$cat.catid}-->" 
											<!--{if in_array($cat[catid],$itemcats)}-->checked<!--{/if}-->
											/>
										<!--{/if}-->
										<!--{$cat.catname}-->
									</li>
									<!--{/foreach}-->
								</ul>
								<ul class="scrollul">
									<h1>商品Tag</h1>
									<!--{foreach $tags tag}-->
									<li>
										<input type="checkbox" value="<!--{$tag.tagid}-->" name="tagid[]" id="tag_<!--{$tag.tagid}-->" 
										<!--{if in_array($tag[tagid],$itemtags)}-->checked<!--{/if}-->
										/>
										<!--{$tag.tagname}-->
									</li>
									<!--{/foreach}-->
								</ul>
							</div>
						</li>
					</ul>

					<ul class="bk_4 clearfix">
						<li>
							<label><em>*</em>商品相册：</label>
							<div id="buttonholder"></div>
							<div class="clear"></div>
						</li>
						<li>
							<label>商品图片：</label>
							<div id="imgtd"  class="left">
								<!--{foreach $imgs img}-->
									<div class="itemupload">
										<div class="forimg"><img src="<!--{$img.imgpath}-->_50x50.jpg" width="50" height="50" /></div>
										<p>
											<a href="javascript:void(0);" onclick="$.oper.up(this);return false;" class="left"></a>
											<a href="javascript:void(0);" onclick="$.oper.del(this);return false;" class="del"></a>
											<a href="javascript:void(0);" onclick="$.oper.down(this);return false;" class="right"></a>
											<input type="hidden" value="<!--{$img.imgpath}-->"  
												name="img[key_<!--{$img.imgid}-->]" class="forval"/>
										</p>
									</div>
								<!--{/foreach}-->
							</div>
						</li>

					</ul>
			</div>

			<ul class="bk none" id="fordesc">
				<li>
					<label>商品详情：</label>
					<p>
						<textarea name="itemdesc" id="itemdesc"><!--{$desc.itemdesc}--></textarea>
					</p>
				</li>
			 </ul>
			
			<ul class="bk none" id="forseo">
				<li>
					<label>页面标题：</label>
					<p>
						<input class="input_tx" name="pagetitle" type="text" value="<!--{$desc.pagetitle}-->"/>
					</p>
				</li>
				<li>
					<label>页面关键词：</label>
					<p>
						<input class="input_tx" name="pagekeywords" type="text" value="<!--{$desc.pagekeywords}-->"/>
					</p>
				</li>
				<li>
					<label>页面描述：</label>
					<p>
						<textarea name="pagedesc" class="text_tx"><!--{$desc.pagedesc}--></textarea>
					</p>
				</li>
			 </ul>
			 <div class="bk none" id="forrel">
				<ul class="bk_1">
					<li>
						<label><a href="javascript:void(0);" onclick="ItemSelect.popitem();return false;" class="bt_style2">相关商品</a></label>
					</li>
				 </ul>
				<table class="tableStyle" id="reltb" border="0" cellspacing="0" cellpadding="0">
					<!--{foreach $itemrels rel}-->
					<tr>
						<td class="forimg">
							<img src="<!--{$rel.itemimg}-->_50x50.jpg" width="50" height="50" class="mid"/>
						</td>
						<td>
							<label for="linktype_<!--{$rel.fitemid}-->_1"> 
								<input type="radio" name="linktype[<!--{$rel.fitemid}-->]" id="linktype_<!--{$rel.fitemid}-->_1" value="1"  <!--{if $rel.linktype == 1}-->checked<!--{/if}-->/> 单项相关
							</label>
							<label for="linktype_<!--{$rel.fitemid}-->_2"> 
								<input type="radio" name="linktype[<!--{$rel.fitemid}-->]" id="linktype_<!--{$rel.fitemid}-->_2" value="2"
								<!--{if $rel.linktype == 2}-->checked<!--{/if}-->
								/>  双项相关
							</label>
							<input type="hidden" value="<!--{$rel.fitemid}-->" name="fitemid[<!--{$rel.fitemid}-->]" />
						</td>
						<td>
							<a href="javascript:void(0);" onclick="$.oper.del(this);return false;"  class="del"></a>
							<a href="javascript:void(0);" onclick="$.oper.up(this);return false;"   class="up"></a>
							<a href="javascript:void(0);" onclick="$.oper.down(this);return false;" class="down"></a>
						</td>
					</tr>
					<!--{/foreach}-->
				</table>
			</div>
			
			<div class="bt_bk2">
				<input type="hidden" name="itemid"	 value="<!--{def($itemid)}-->" />
				<input type="hidden" name="opertype" value="<!--{$opertype}-->" />
				<a href="javascript:void(0);" class="btn" onclick="jssubmit('item');return false;"><span>保存</span></a>
			</div>
		</form>
		</div>
		<b class="b4b"></b><b class="b3b"></b><b class="b2b"></b><b class="b1b"></b>
	</div>
</div>

<div class="none" id="forimgnone">
	<div class="itemupload">
		<div class="forimg"></div>
		<p>
			<a href="javascript:void(0);" onclick="$.oper.up(this);return false;" class="left"></a>
			<a href="javascript:void(0);" onclick="$.oper.del(this);return false;" class="del"></a>
			<a href="javascript:void(0);" onclick="$.oper.down(this);return false;" class="right"></a>
			<input type="hidden" value=""  name="img[]" class="forval"/>
		</p>
	</div>
</div>

<!--规格box-->
<div id="specbox" class="none">
	<p style="margin:5px 0;text-align:center;"><a href="javascript:void(0);" onclick="$('#specbox').hide();return false;">关闭</a></p>
	<!--{foreach $specs spec}-->
	<ul id="specbox_<!--{$spec.specid}-->" class="none"></ul>
	<!--{/foreach}-->
</div>

<table class="none" border="0" cellspacing="0" cellpadding="0">
	<tbody id="forspecnone">
		<tr align="center">
			<td><a href="javascript:void(0);" class="del" onclick="$.oper.del(this);return false;"></a></td>
			<!--{foreach $specs spec}-->
				<td class="forspecnone_<!--{$spec.specid}-->">
					<a href="javascript:void(0);" onclick="$.specval.select(this,<!--{$spec.specid}-->);return false;">请选择</a>
					<input type="hidden" value="" name="spec[<!--{$spec.specid}-->][]"/>
				</td>
			<!--{/foreach}-->
			<td><input type="text" value="" name="pprice[]"		class="input_tx mini calprice"	   onblur="cal('price')"/></td>
			<td><input type="text" value="" name="pinventory[]" class="input_tx mini calinventory" onblur="cal('inventory')"/></td>
			<td>
				<input type="text" value="" name="pbn[]" class="input_tx short"/>
			</td>
		</tr>
	</tbody>
	<tbody id="forrelnone">
		<tr>
			<td class="forimg">
			</td>
			<td>
				<label for="linktype_{itemid}_1"> 
					<input type="radio" name="linktype[{itemid}]" id="linktype_{itemid}_1" value="1" checked/> 单项相关
				</label>
				<label for="linktype_{itemid}_2"> 
					<input type="radio" name="linktype[{itemid}]" id="linktype_{itemid}_2" value="2"/>  双项相关
				</label>
				<input type="hidden" value="{itemid}" name="fitemid[{itemid}]" />
			</td>
			<td>
				<a href="javascript:void(0);" onclick="$.oper.del(this);return false;"  class="del"></a>
				<a href="javascript:void(0);" onclick="$.oper.up(this);return false;"   class="up"></a>
				<a href="javascript:void(0);" onclick="$.oper.down(this);return false;" class="down"></a>
			</td>
		</tr>
	</tbody>
</table>
<!--{include(file='foot.html')}-->
<script type="text/javascript" src="template/admin/js/item.js"></script>
<script type="text/javascript">
$(function(){
	$(".shouldclick").each(function(){
		$(this)[0].click();
	});
	$("#a<!--{$cur}-->").click();
	
	ItemSelect.setPopUrl("<!--{url('admin','select','selectitem','type=rel')}-->");

	$("#itemdesc").xheditor({upImgUrl:"<!--{url('admin','uploadfile','pic')}-->"});

	itemupload("<!--{url('admin','uploadfile','item')}-->");
});
</script>